
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>页面与组件 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    
    <link rel="prev" href="nml.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    入门
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../introduction/environment.html">
            
                <a href="../introduction/environment.html">
            
                    
                    环境搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../introduction/hello.html">
            
                <a href="../introduction/hello.html">
            
                    
                    HelloWorld
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../introduction/dev-and-debug.html">
            
                <a href="../introduction/dev-and-debug.html">
            
                    
                    开发与调试
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    参考
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="file.html">
            
                <a href="file.html">
            
                    
                    文件组织
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="manifest.html">
            
                <a href="manifest.html">
            
                    
                    manifest文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="nml.html">
            
                <a href="nml.html">
            
                    
                    nml文件
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.4" data-path="page.html">
            
                <a href="page.html">
            
                    
                    页面与组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    组件
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../component/general.html">
            
                <a href="../component/general.html">
            
                    
                    通用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../component/container.html">
            
                <a href="../component/container.html">
            
                    
                    容器组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../component/basics.html">
            
                <a href="../component/basics.html">
            
                    
                    基础组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../component/form.html">
            
                <a href="../component/form.html">
            
                    
                    表单组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../component/media.html">
            
                <a href="../component/media.html">
            
                    
                    媒体组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    接口
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../api/general.html">
            
                <a href="../api/general.html">
            
                    
                    通用规则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../api/basic.html">
            
                <a href="../api/basic.html">
            
                    
                    基本功能
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../api/interface.html">
            
                <a href="../api/interface.html">
            
                    
                    界面交互
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../api/request.html">
            
                <a href="../api/request.html">
            
                    
                    网络访问
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../api/storage.html">
            
                <a href="../api/storage.html">
            
                    
                    文件数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../api/system.html">
            
                <a href="../api/system.html">
            
                    
                    系统能力
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="../api/media.html">
            
                <a href="../api/media.html">
            
                    
                    图形图像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="../api/service.html">
            
                <a href="../api/service.html">
            
                    
                    厂商服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="../api/third.html">
            
                <a href="../api/third.html">
            
                    
                    第三方服务
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >页面与组件</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x9875;&#x9762;&#x4E0E;&#x7EC4;&#x4EF6;">&#x9875;&#x9762;&#x4E0E;&#x7EC4;&#x4EF6;</h2>
<h3 id="template-&#x6A21;&#x677F;">template &#x6A21;&#x677F;</h3>
<p>&#x7C7B;&#x4F3C;HTML&#x7684;&#x6807;&#x7B7E;&#x8BED;&#x8A00;&#xFF0C;&#x7ED3;&#x5408;&#x57FA;&#x7840;&#x7EC4;&#x4EF6;&#x3001;&#x81EA;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;&#x3001;&#x4E8B;&#x4EF6;&#xFF0C;&#x6784;&#x5EFA;&#x51FA;&#x9875;&#x9762;&#x7684;&#x7ED3;&#x6784;&#x3002;</p>
<p>&#x6A21;&#x677F;&#x4E2D;&#x53EA;&#x80FD;&#x6709;1&#x4E2A;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x5982;&#xFF1A;div&#xFF1B;&#x8BF7;&#x4E0D;&#x8981;&#x5728; <code>&lt;template&gt;</code> &#x4E0B;&#x5B58;&#x5728;&#x591A;&#x4E2A;&#x6839;&#x8282;&#x70B9;&#xFF0C;&#x4E5F;&#x4E0D;&#x8981;&#x4F7F;&#x7528; <code>block</code> &#x4F5C;&#x4E3A;&#x6839;&#x8282;&#x70B9;&#x3002;</p>
<p><strong>&#x6570;&#x636E;&#x7ED1;&#x5B9A;</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>{{message}}<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">module</span>.exports = {
    data: {
      message: <span class="hljs-string">&apos;Hello World!&apos;</span>
    }
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p><strong>&#x4E8B;&#x4EF6;&#x7ED1;&#x5B9A;</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x6B63;&#x5E38;&#x683C;&#x5F0F; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">&quot;press&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x7F29;&#x5199; --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;press&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">module</span>.exports = {
    press: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">e</span>) </span>{
      <span class="hljs-keyword">this</span>.title = <span class="hljs-string">&apos;Hello&apos;</span>
    }
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>&#x4E8B;&#x4EF6;&#x56DE;&#x8C03;&#x652F;&#x6301;&#x7684;&#x5199;&#x6CD5;&#xFF08;&#x5176;&#x4E2D;&#x82B1;&#x62EC;&#x53F7;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#xFF09;&#xFF1A;</p>
<ul>
<li>&quot;fn&quot;&#xFF1A;fn&#x4E3A;&#x4E8B;&#x4EF6;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x540D;&#xFF08;&#x5728; <code>&lt;script&gt;</code> &#x4E2D;&#x6709;&#x5BF9;&#x5E94;&#x7684;&#x51FD;&#x6570;&#x5B9E;&#x73B0;&#xFF09;&#x3002;</li>
<li>&quot;fn(a,b)&quot;&#xFF1A;&#x51FD;&#x6570;&#x53C2;&#x6570;&#x4F8B;&#x5982;a&#xFF0C;b&#x53EF;&#x4EE5;&#x662F;&#x5E38;&#x91CF;&#xFF0C;&#x6216;&#x8005;&#x662F;&#x5728; <code>&lt;script&gt;</code> &#x7684;data&#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x53D8;&#x91CF;&#xFF08;&#x524D;&#x9762;&#x4E0D;&#x7528;&#x5199;this.&#xFF09;&#x3002;</li>
<li>&quot;a+b&quot;&#xFF1A;&#x8868;&#x8FBE;&#x5F0F;&#xFF0C;&#x5176;&#x4E2D;a,b&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4E0E;&#x4E0A;&#x9762;&#x76F8;&#x540C;&#x3002;</li>
</ul>
<p>&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x88AB;&#x8C03;&#x7528;&#x65F6;&#xFF0C;&#x4F1A;&#x5728;&#x53C2;&#x6570;&#x5217;&#x8868;&#x672B;&#x5C3E;&#x81EA;&#x52A8;&#x6DFB;&#x52A0;&#x4E00;&#x4E2A; ev &#x53C2;&#x6570;&#xFF0C;&#x901A;&#x8FC7; evt &#x53C2;&#x6570;&#x8BBF;&#x95EE;&#x56DE;&#x8C03;&#x4E8B;&#x4EF6;&#x76F8;&#x5173;&#x4E0A;&#x4E0B;&#x6587;&#x6570;&#x636E;&#xFF08;&#x6570;&#x636E;&#x5185;&#x5BB9;&#x5177;&#x4F53;&#x53C2;&#x770B;&#x7EC4;&#x4EF6;&#x56DE;&#x8C03;&#x4E8B;&#x4EF6;&#x8BF4;&#x660E;&#xFF09;&#xFF0C;&#x4F8B;&#x5982;&#x70B9;&#x51FB;&#x4E8B;&#x4EF6;&#x7684;&#x70B9;&#x51FB;&#x4F4D;&#x7F6E; x&#xFF0C;y&#x3002;</p>
<p><strong>&#x5217;&#x8868;&#x6E32;&#x67D3;</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;list-container&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;{{list}}&quot;</span> <span class="hljs-attr">tid</span>=<span class="hljs-string">&quot;id&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>{{$idx}}<span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>{{$item.id}}<span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">module</span>.exports = {
    data: {
      list: [{
        id: <span class="hljs-number">1</span>
      }, {
        id: <span class="hljs-number">2</span>
      }]
    }
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>&#x6807;&#x7B7E;&#x4E2D;&#x7684; tid &#x7528;&#x4E8E;&#x6307;&#x5B9A;&#x4F5C;&#x4E3A;&#x5B9A;&#x4E49;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x552F;&#x4E00; ID &#x7684;&#x5B57;&#x6BB5;&#x540D;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#xFF0C;&#x5219;&#x9ED8;&#x8BA4;&#x91C7;&#x7528;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#xFF08;$idx&#xFF09;&#x4F5C;&#x4E3A;&#x552F;&#x4E00; ID&#xFF1B;tid &#x7684;&#x4F5C;&#x7528;&#x662F;&#x4E3A;&#x4E86;&#x5143;&#x7D20;&#x8282;&#x70B9;&#x91CD;&#x7528;&#xFF0C;&#x4F18;&#x5316; for &#x5FAA;&#x73AF;&#x7684;&#x91CD;&#x7ED8;&#x6548;&#x7387;&#x3002;</p>
<p>&#x4F8B;&#x5982; <code>tid=&quot;id&quot;</code> &#x8868;&#x793A; <code>$item.id</code> &#x4F5C;&#x4E3A;&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x552F;&#x4E00; ID&#x3002;</p>
<p>for &#x5FAA;&#x73AF;&#x652F;&#x6301;&#x7684;&#x5199;&#x6CD5;&#xFF08;&#x5176;&#x4E2D;&#x82B1;&#x62EC;&#x53F7;&#x53EF;&#x4EE5;&#x7701;&#x7565;&#xFF09;&#xFF1A;</p>
<ul>
<li>for=&quot;list&quot;&#xFF1A;list &#x4E3A;&#x6570;&#x7EC4;&#x5BF9;&#x8C61;&#xFF0C;&#x9ED8;&#x8BA4;&#x5143;&#x7D20;&#x53D8;&#x91CF;&#x4E3A; $item&#x3002;</li>
<li>for=&quot;value in list&quot;&#xFF1A;value &#x4E3A;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x5143;&#x7D20;&#x53D8;&#x91CF;&#xFF0C;&#x9ED8;&#x8BA4;&#x5143;&#x7D20;&#x7D22;&#x5F15;&#x4E3A; $idx&#x3002;</li>
<li>for=&quot;(index,value) in list&quot;&#xFF1A;index &#x4E3A;&#x5143;&#x7D20;&#x7D22;&#x5F15;&#xFF0C;value &#x4E3A;&#x5143;&#x7D20;&#x53D8;&#x91CF;&#x3002;</li>
<li>tid &#x6307;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x5C5E;&#x6027;&#x5FC5;&#x987B;&#x5B58;&#x5728;&#xFF0C;&#x5426;&#x5219;&#x53EF;&#x80FD;&#x5F15;&#x8D77;&#x8FD0;&#x884C;&#x5F02;&#x5E38;&#x3002;</li>
<li>tid &#x6307;&#x5B9A;&#x7684;&#x6570;&#x636E;&#x5C5E;&#x6027;&#x8981;&#x4FDD;&#x8BC1;&#x552F;&#x4E00;&#xFF0C;&#x5982;&#x679C;&#x53D1;&#x751F;&#x91CD;&#x590D;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x9020;&#x6210;&#x6027;&#x80FD;&#x95EE;&#x9898;&#x3002;</li>
</ul>
<p><strong>&#x6761;&#x4EF6;&#x6E32;&#x67D3;</strong></p>
<p>&#x5206;&#x4E3A;2&#x79CD;&#xFF1A;if/elif/else &#x548C; show&#x3002;&#x5B83;&#x4EEC;&#x7684;&#x533A;&#x522B;&#x5728;&#x4E8E;&#xFF1A;</p>
<ul>
<li>if &#x4E3A; false &#x65F6;&#xFF0C;&#x7EC4;&#x4EF6;&#x4F1A;&#x4ECE; VDOM &#x4E2D;&#x79FB;&#x9664;&#xFF0C;&#x800C; show &#x4EC5;&#x4EC5;&#x662F;&#x6E32;&#x67D3;&#x65F6;&#x4E0D;&#x53EF;&#x89C1;&#xFF0C;&#x7EC4;&#x4EF6;&#x4F9D;&#x7136;&#x5B58;&#x5728;&#x4E8E; VDOM &#x4E2D;&#x3002;</li>
<li>if/elif/else&#x8282;&#x70B9;&#x5FC5;&#x987B;&#x662F;&#x76F8;&#x90BB;&#x7684;&#x5144;&#x5F1F;&#x8282;&#x70B9;&#xFF0C;&#x5426;&#x5219;&#x65E0;&#x6CD5;&#x901A;&#x8FC7;&#x7F16;&#x8BD1;&#x3002;</li>
</ul>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span> <span class="hljs-attr">if</span>=<span class="hljs-string">&quot;{{show}}&quot;</span>&gt;</span> Hello-1 <span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span> <span class="hljs-attr">elif</span>=<span class="hljs-string">&quot;{{display}}&quot;</span>&gt;</span> Hello-2 <span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span> <span class="hljs-attr">else</span>&gt;</span> Hello-3 <span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">module</span>.exports = {
    data: {
      show: <span class="hljs-literal">false</span>
    }
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>show &#x7B49;&#x540C;&#x4E8E; <code>display=none</code>&#xFF0C;&#x76EE;&#x524D;&#x53EA;&#x7528;&#x4E8E;&#x7CFB;&#x7EDF;&#x539F;&#x751F;&#x7EC4;&#x4EF6;&#xFF0C;&#x5BF9;&#x81EA;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;&#x4E0D;&#x751F;&#x6548;&#x3002;&#x81EA;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; props &#x4F20;&#x5165;&#x53C2;&#x6570;&#xFF0C;&#x5728;&#x81EA;&#x5DF1;&#x5185;&#x90E8;&#x4F7F;&#x7528; show &#x6765;&#x63A7;&#x5236;&#x662F;&#x5426;&#x53EF;&#x89C1;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">text</span> <span class="hljs-attr">show</span>=<span class="hljs-string">&quot;{{visible}}&quot;</span>&gt;</span> Hello <span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">module</span>.exports = {
    data: {
      visible: <span class="hljs-literal">false</span>
    }
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p><strong>&#x903B;&#x8F91;&#x63A7;&#x5236;&#x5757;</strong></p>
<p>&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <block> &#x5B9E;&#x73B0;&#x66F4;&#x4E3A;&#x7075;&#x6D3B;&#x7684;&#x5FAA;&#x73AF;/&#x6761;&#x4EF6;&#x6E32;&#x67D3;&#xFF1B;
&#x6CE8;&#x610F; <block> &#x76EE;&#x524D;&#x53EA;&#x652F;&#x6301; for &#x548C; if/elif/else &#x5C5E;&#x6027;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#x4EFB;&#x4F55;&#x5C5E;&#x6027;&#xFF0C;<block> &#x5219;&#x5728;&#x6784;&#x5EFA;&#x65F6;&#x88AB;&#x5F53;&#x4F5C;&quot;&#x900F;&#x660E;&quot;&#x8282;&#x70B9;&#x5BF9;&#x5F85;&#xFF0C;&#x5176;&#x5B50;&#x8282;&#x70B9;&#x88AB;&#x6DFB;&#x52A0;&#x5230; <block> &#x7684;&#x7236;&#x8282;&#x70B9;&#x4E0A;&#x3002;</block></block></block></block></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">list</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">block</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;cities&quot;</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">list-item</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;city&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>{{$item.name}}<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">list-item</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">block</span> <span class="hljs-attr">for</span>=<span class="hljs-string">&quot;$item.spots&quot;</span> <span class="hljs-attr">if</span>=<span class="hljs-string">&quot;false&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">list-item</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;spot&quot;</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>{{$item.address}}<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">list-item</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">block</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">block</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">list</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-built_in">module</span>.exports = {
    data: {
      cities: [{
          name: <span class="hljs-string">&quot;beijing&quot;</span>,
          spots: [{
            name: <span class="hljs-string">&quot;XXX&quot;</span>,
            address: <span class="hljs-string">&quot;XXX&quot;</span>
          }, {
            name: <span class="hljs-string">&quot;XXX&quot;</span>,
            address: <span class="hljs-string">&quot;XXX&quot;</span>
          }]
        },
        {
          name: <span class="hljs-string">&quot;shanghai&quot;</span>,
          spots: [{
            name: <span class="hljs-string">&quot;XXX&quot;</span>,
            address: <span class="hljs-string">&quot;XXX&quot;</span>
          }, {
            name: <span class="hljs-string">&quot;XXX&quot;</span>,
            address: <span class="hljs-string">&quot;XXX&quot;</span>
          }]
        }
      ]
    }
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p><strong>&#x5F15;&#x5165;&#x81EA;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;</strong></p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">import</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&apos;comp&apos;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&apos;./comp&apos;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">import</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">comp</span> <span class="hljs-attr">prop1</span>=<span class="hljs-string">&apos;xxxx&apos;</span> <span class="hljs-attr">onevent1</span>=<span class="hljs-string">&quot;bindParentVmMethod1&quot;</span> @<span class="hljs-attr">event-type1</span>=<span class="hljs-string">&quot;bindParentVmMethod1&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">comp</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<p>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x8BBE;&#x7F6E; name &#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x9ED8;&#x8BA4;&#x91C7;&#x7528; src &#x7684;&#x6587;&#x4EF6;&#x540D;&#x4F5C;&#x4E3A;&#x7EC4;&#x4EF6;&#x540D;</p>
<p>src &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x7EC4;&#x4EF6; nml &#x6587;&#x4EF6;&#x4F4D;&#x7F6E;&#xFF0C;&#x53EF;&#x4EE5;&#x7701;&#x7565; .nml &#x540E;&#x7F00;&#x3002;</p>
<ul>
<li>&#x7EC4;&#x4EF6;&#x540D;&#x4E0D;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#xFF0C;&#x9ED8;&#x8BA4;&#x7EDF;&#x4E00;&#x91C7;&#x7528;&#x5C0F;&#x5199;&#x3002;</li>
<li>&#x901A;&#x8FC7; (on|@)event1 &#x8BED;&#x6CD5;&#x7ED1;&#x5B9A;&#x81EA;&#x5B9A;&#x4E49;&#x5B50;&#x7EC4;&#x4EF6;&#x7684; event1 &#x4E8B;&#x4EF6;&#xFF0C;&#x89E6;&#x53D1;&#x4E8B;&#x4EF6; <code>childVm.$emit(&apos;event1&apos;, { params: &apos;&#x4F20;&#x9012;&#x53C2;&#x6570;&apos; })</code> &#x65F6;&#x6267;&#x884C;&#x7236;&#x7EC4;&#x4EF6;&#x7684;&#x65B9;&#x6CD5;&#xFF1A;bindParentVmMethod1&#x3002;</li>
<li>&#x6807;&#x7B7E;&#x4E0A;&#x58F0;&#x660E;&#x4E8B;&#x4EF6;&#x540D;&#x79F0;&#x91C7;&#x7528;-&#x8FDE;&#x63A5;&#xFF0C;&#x4E0D;&#x8981;&#x4F7F;&#x7528;&#x9A7C;&#x5CF0;&#x5F0F;&#xFF0C;&#x6765;&#x505A;&#x54CD;&#x5E94;&#x4E0E;&#x65B9;&#x6CD5;&#x7684;&#x5173;&#x8054;&#xFF0C;&#x5373;&#xFF1A;&#x4F7F;&#x7528; event-type1 &#x8868;&#x793A;&#x7ED1;&#x5B9A; eventType1 &#x4E8B;&#x4EF6;&#x3002;</li>
</ul>
<p><strong>&#x63D2;&#x5165;&#x81EA;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;</strong></p>
<p>&#x7EC4;&#x4EF6;&#x4E2D;&#x901A;&#x8FC7;&#x6807;&#x7B7E;&#x6765;&#x5B9A;&#x4E49;&#x5B50;&#x7EC4;&#x4EF6;&#x63D2;&#x5165;&#x4F4D;&#x7F6E;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;</p>
<p>&#x7EC4;&#x4EF6; com-a &#x7684;&#x6A21;&#x677F;&#x5B9A;&#x4E49;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>header<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">slot</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>footer<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<p>&#x5728;&#x9875;&#x9762;&#x4F7F;&#x7528;&#x7EC4;&#x4EF6; comA&#xFF0C;&#x5B9A;&#x4E49;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">import</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;comp-a&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;./comp-a&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">import</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">com-a</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>body<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">com-a</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
</code></pre>
<p>&#x5219;&#x5728;&#x9875;&#x9762;&#x6E32;&#x67D3;&#x65F6;&#xFF0C;&#x7EC4;&#x4EF6; comA &#x53D8;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>header<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>body<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">text</span>&gt;</span>footer<span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
<h3 id="style&#x6837;&#x5F0F;">Style&#x6837;&#x5F0F;</h3>
<p>&#x7528;&#x4E8E;&#x63CF;&#x8FF0; template &#x6A21;&#x677F;&#x7684;&#x7EC4;&#x4EF6;&#x6837;&#x5F0F;&#xFF0C;&#x51B3;&#x5B9A;&#x7EC4;&#x4EF6;&#x5E94;&#x8BE5;&#x5982;&#x4F55;&#x663E;&#x793A;&#x3002;</p>
<p>&#x6837;&#x5F0F;&#x5E03;&#x5C40;&#x91C7;&#x7528;CSS Flexbox&#xFF08;&#x5F39;&#x6027;&#x76D2;&#xFF09;&#x6837;&#x5F0F;&#xFF0C;&#x9488;&#x5BF9;&#x90E8;&#x5206;&#x539F;&#x751F;&#x7EC4;&#x4EF6;&#xFF0C;&#x5BF9; CSS &#x8FDB;&#x884C;&#x4E86;&#x5C11;&#x91CF;&#x7684;&#x6269;&#x5145;&#x4EE5;&#x53CA;&#x4FEE;&#x6539;&#x3002;</p>
<p>&#x4E3A;&#x4E86;&#x89E3;&#x51B3;&#x5C4F;&#x5E55;&#x9002;&#x914D;&#x95EE;&#x9898;&#xFF0C;&#x6240;&#x6709;&#x4E0E;&#x5927;&#x5C0F;&#x76F8;&#x5173;&#x7684;&#x6837;&#x5F0F;&#xFF08;&#x4F8B;&#x5982;width&#x3001;font-size&#xFF09;&#x5747;&#x4EE5;&#x57FA;&#x51C6;&#x5BBD;&#x5EA6;&#xFF08;&#x9ED8;&#x8BA4;750px&#xFF09;&#x4E3A;&#x57FA;&#x7840;&#xFF0C;&#x6839;&#x636E;&#x5B9E;&#x9645;&#x5C4F;&#x5E55;&#x5BBD;&#x5EA6;&#x8FDB;&#x884C;&#x7F29;&#x653E;&#xFF0C;&#x4F8B;&#x5982;width:100px&#xFF0C;&#x5728;1500px&#x5BBD;&#x5EA6;&#x5C4F;&#x5E55;&#x4E0A;&#xFF0C;width&#x5B9E;&#x9645;&#x4E0A;&#x4E3A;200px&#x3002;</p>
<p>&#x6587;&#x4EF6;&#x5BFC;&#x5165;</p>
<p>&#x652F;&#x6301;2&#x79CD;&#x5BFC;&#x5165;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- &#x5BFC;&#x5165;&#x5916;&#x90E8;&#x6587;&#x4EF6;, &#x4EE3;&#x66FF;style&#x5185;&#x90E8;&#x6837;&#x5F0F; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;./style.css&quot;</span>&gt;</span><span class="undefined"></span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- &#x5408;&#x5E76;&#x5916;&#x90E8;&#x6587;&#x4EF6; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
@<span class="hljs-keyword">import</span> <span class="hljs-string">&apos;./style.css&apos;</span>;
<span class="hljs-selector-tag">a</span>{
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<p><strong>&#x6A21;&#x677F;&#x5185;&#x90E8;&#x6837;&#x5F0F;</strong></p>
<p>&#x652F;&#x6301;&#x4F7F;&#x7528;style&#x3001;class&#x5C5E;&#x6027;&#x6765;&#x63A7;&#x5236;&#x7EC4;&#x4EF6;&#x7684;&#x6837;&#x5F0F;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!-- &#x5185;&#x8054;inline --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;color:red; margin: 10px;&quot;</span> /&gt;</span>
<span class="hljs-comment">&lt;!-- class&#x58F0;&#x660E; --&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;normal append&quot;</span> /&gt;</span>*
</code></pre>
<p><strong>&#x9009;&#x62E9;&#x5668;</strong></p>
<p>&#x652F;&#x6301;&#x7684;&#x9009;&#x62E9;&#x5668;&#x5982;&#x4E0B;&#x8868;&#x6240;&#x793A;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x9009;&#x62E9;&#x5668;</th>
<th style="text-align:left">&#x6837;&#x4F8B;</th>
<th style="text-align:left">&#x6837;&#x4F8B;&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">.class</td>
<td style="text-align:left">.intro</td>
<td style="text-align:left">&#x9009;&#x62E9;&#x6240;&#x6709;&#x62E5;&#x6709; class=&quot;intro&quot; &#x7684;&#x7EC4;&#x4EF6;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">#id</td>
<td style="text-align:left">#firstname</td>
<td style="text-align:left">&#x9009;&#x62E9;&#x62E5;&#x6709; id=&quot;firstname&quot; &#x7684;&#x7EC4;&#x4EF6;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">tag</td>
<td style="text-align:left">div</td>
<td style="text-align:left">&#x9009;&#x62E9;&#x6240;&#x6709; div &#x7EC4;&#x4EF6;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">,</td>
<td style="text-align:left">.a, .b</td>
<td style="text-align:left">&#x9009;&#x62E9;&#x6240;&#x6709;class=&quot;.a&quot; &#x4EE5;&#x53CA;class=&quot;.b&quot;&#x7684;&#x7EC4;&#x4EF6;&#x3002;</td>
</tr>
</tbody>
</table>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="undefined">
// &#x5355;&#x4E2A;&#x9009;&#x62E9;&#x5668;
text {
}
.class-abc {
}
#idAbc {
}

// &#x540C;&#x4E00;&#x6837;&#x5F0F;&#x9002;&#x5E94;&#x591A;&#x4E2A;&#x9009;&#x62E9;&#x5668;
.font-text,.font-comma {
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<p>&#x9009;&#x62E9;&#x5668;&#x58F0;&#x660E;&#x7684;&#x53D8;&#x5316;&#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x5143;&#x7D20;&#x91CD;&#x65B0;&#x7ED8;&#x5236;&#x3002;&#x4E3A;&#x4E86;&#x51CF;&#x5C11;&#x9009;&#x62E9;&#x5668;&#x53D8;&#x5316;&#x5F15;&#x8D77;&#x7684;DOM&#x66F4;&#x65B0;&#x6570;&#x91CF;&#xFF0C;&#x5F53;&#x524D;&#x53EA;&#x652F;&#x6301;&#xFF1A;CSS&#x58F0;&#x660E;&#x7684;&#x591A;&#x4E2A;&#x9009;&#x62E9;&#x5668;&#x4E2D;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x89C4;&#x5219;&#x7684;&#x53D8;&#x66F4;&#x5BF9;DOM&#x7684;&#x66F4;&#x65B0;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;{{docBody}}&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">text</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;{{rowDesc}}&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;&#x63CF;&#x8FF0;&#x5185;&#x5BB9;&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">text</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
  <span class="hljs-selector-class">.row-desc1</span> {
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#ff0000</span>;
  }

  <span class="hljs-selector-class">.row-desc2</span> {
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#0000ff</span>;
  }

  <span class="hljs-selector-class">.row-desc1</span> {
    <span class="hljs-attribute">color</span>: <span class="hljs-number">#00ff00</span>;
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
  <span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> {
    data: {
      rowDesc: <span class="hljs-string">&quot;row-desc1&quot;</span>,
      docBody: <span class="hljs-string">&quot;doc-body&quot;</span>
    }
  }
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>&#x4EE5;&#x4E0A;&#x7684;&#x4EE3;&#x7801;&#x793A;&#x4F8B;&#xFF0C;&#x5F53;&#x6211;&#x4EEC;&#x628A; rowDesc &#x53D8;&#x91CF;&#x4ECE; row-desc1 &#x53D8;&#x4E3A; row-desc2 &#x65F6;&#x662F;&#x901A;&#x77E5; Native &#x66F4;&#x65B0;&#x8282;&#x70B9;&#x6837;&#x5F0F;&#xFF0C;&#x4F46;&#x662F;&#x5982;&#x679C;&#x628A; docBody &#x53D8;&#x91CF;&#x4ECE; doc-body &#x53D8;&#x4E3A; doc-body2&#xFF0C;&#x662F;&#x4E0D;&#x4F1A;&#x901A;&#x77E5; DOM &#x66F4;&#x65B0;&#x7684;&#x3002;</p>
<p>&#x56E0;&#x4E3A; doc-body &#x4E0D;&#x662F;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x9009;&#x62E9;&#x5668;&#xFF0C;&#x975E;&#x672B;&#x5C3E;&#x7684;&#x9009;&#x62E9;&#x5668;&#x53D8;&#x66F4;&#x6709;&#x53EF;&#x80FD;&#x5F71;&#x54CD;&#x5F88;&#x591A; DOM &#x5143;&#x7D20;&#xFF0C;&#x4ECE;&#x800C;&#x5F71;&#x54CD;&#x5230;&#x6E32;&#x67D3;&#x6027;&#x80FD;&#x3002;</p>
<p><strong>&#x9009;&#x62E9;&#x5668;&#x4F18;&#x5148;&#x7EA7;</strong></p>
<p>&#x5F53;&#x524D;&#x6837;&#x5F0F;&#x7684;&#x9009;&#x62E9;&#x5668;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#x8BA1;&#x7B97;&#x4FDD;&#x6301;&#x4E0E;&#x6D4F;&#x89C8;&#x5668;&#x4E00;&#x81F4;&#xFF0C;&#x662F;&#x6D4F;&#x89C8;&#x5668; CSS &#x6E32;&#x67D3;&#x7684;&#x4E00;&#x4E2A;&#x5B50;&#x96C6;&#xFF08;&#x4EC5;&#x652F;&#x6301;&#xFF1A;inline&#xFF0C;id&#xFF0C;class&#xFF0C;tag&#xFF0C;&#x540E;&#x4EE3;&#xFF0C;&#x76F4;&#x63A5;&#x540E;&#x4EE3;&#xFF09;</p>
<p>&#x9009;&#x62E9;&#x5668;&#x4F18;&#x5148;&#x7EA7;&#x89C4;&#x5219;&#x5982;&#x4E0B;&#xFF08;&#x5047;&#x8BBE;&#x591A;&#x6761; CSS &#x58F0;&#x660E;&#x5339;&#x914D;&#x5230;&#x540C;&#x4E00;&#x4E2A;&#x5143;&#x7D20; div&#xFF09;&#xFF0C;&#x5E94;&#x7528;&#x5728;&#x8BE5;&#x5143;&#x7D20;&#x4E0A;&#x7684; CSS &#x58F0;&#x660E;&#x603B;&#x4F53;&#x4F18;&#x5148;&#x7EA7;&#x662F;&#xFF1A;<code>inline &gt; #id &gt; .class &gt; tag</code>&#xFF0C;&#x8FD9;&#x56DB;&#x5927;&#x7C7B;&#x5339;&#x914D;&#x5230;&#x8BE5;&#x5143;&#x7D20;&#x7684;&#x591A;&#x4E2A; CSS &#x58F0;&#x660E;&#x3002;</p>
<p><strong>&#x6837;&#x5F0F;&#x9884;&#x7F16;&#x8BD1;</strong></p>
<p>&#x76EE;&#x524D;&#x652F;&#x6301; less&#xFF0C;sass &#x7684;&#x9884;&#x7F16;&#x8BD1;&#x3002;</p>
<pre><code class="lang-html"><span class="hljs-comment">&lt;!--&#x5BFC;&#x5165;&#x5916;&#x90E8;&#x6587;&#x4EF6;, &#x4EE3;&#x66FF;style&#x5185;&#x90E8;&#x6837;&#x5F0F;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;less&quot;</span> <span class="hljs-attr">src</span>=<span class="hljs-string">&quot;./lessFile.less&quot;</span>&gt;</span><span class="undefined">
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
<span class="hljs-comment">&lt;!--&#x5408;&#x5E76;&#x5916;&#x90E8;&#x6587;&#x4EF6;--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;less&quot;</span>&gt;</span><span class="undefined">
@import &apos;./lessFile.less&apos;;

.page-less {
  #testTag {
    .less-font-text,
    .less-font-comma {
      font-size: 60px;
    }
  }
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<p><strong>&#x4F2A;&#x7C7B;</strong></p>
<p>&#x4EFB;&#x4F55;&#x7EC4;&#x4EF6;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x662F;boolean&#x7C7B;&#x578B;&#x4E14;&#x9ED8;&#x8BA4;&#x503C;&#x4E3A;false&#x65F6;&#xFF0C;&#x5747;&#x53EF;&#x901A;&#x8FC7;&#x8BE5;&#x5C5E;&#x6027;&#x540D;&#x5B57;&#x6765;&#x58F0;&#x660E;&#x4F2A;&#x7C7B;&#xFF0C;&#x5F53;&#x5C5E;&#x6027;&#x53D8;&#x4E3A;true&#x65F6;&#x4F2A;&#x7C7B;&#x751F;&#x6548;&#xFF0C;&#x4F8B;&#x5982;&#x6240;&#x6709;&#x7EC4;&#x4EF6;&#x7684;disabled&#x5C5E;&#x6027;&#x3001;input&#x7EC4;&#x4EF6;&#x7684;checked&#x5C5E;&#x6027;&#x7B49;&#x3002;</p>
<p>&#x53E6;&#x5916;&#x90E8;&#x5206;&#x7EC4;&#x4EF6;&#x4F1A;&#x6709;&#x5176;&#x4ED6;&#x5F62;&#x5F0F;&#x7684;&#x4F2A;&#x7C7B;&#x652F;&#x6301;&#xFF0C;&#x6BD4;&#x5982;input&#x7EC4;&#x4EF6;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E3B;&#x52A8;&#x8C03;&#x7528;focus&#x65B9;&#x6CD5;&#xFF0C;&#x6216;&#x8005;&#x7528;&#x6237;&#x64CD;&#x4F5C;&#x83B7;&#x5F97;&#x7126;&#x70B9;&#xFF0C;&#x4F7F;&#x5F97;focus&#x4F2A;&#x7C7B;&#x751F;&#x6548;&#xFF0C;&#x8BE6;&#x60C5;&#x8BF7;&#x53C2;&#x8003;&#x5404;&#x7EC4;&#x4EF6;&#x5185;&#x90E8;&#x8BF4;&#x660E;&#x3002;</p>
<p>&#x4F2A;&#x7C7B;&#x5199;&#x6CD5;&#x4E3E;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;button&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;btn&quot;</span> <span class="hljs-attr">disabled</span>=<span class="hljs-string">&quot;{{btndisabled}}&quot;</span>&gt;</span>Click<span class="hljs-tag">&lt;/<span class="hljs-name">input</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">style</span>&gt;</span><span class="css">
<span class="hljs-selector-class">.btn</span> {
  <span class="hljs-attribute">width</span>: <span class="hljs-number">360px</span>;
  <span class="hljs-attribute">height</span>: <span class="hljs-number">180px</span>;
  <span class="hljs-attribute">background-color</span>: red;
}

<span class="hljs-selector-class">.btn</span><span class="hljs-selector-pseudo">:disabled</span> {
  <span class="hljs-attribute">background-color</span>: green;
}
</span><span class="hljs-tag">&lt;/<span class="hljs-name">style</span>&gt;</span>
</code></pre>
<p>&#x5F53;&#x7EC4;&#x4EF6;&#x7684;disabled&#x5C5E;&#x6027;&#x53D8;&#x4E3A;true&#x65F6;&#xFF0C;disabled&#x4F2A;&#x7C7B;&#x7684;&#x6837;&#x5F0F;&#x751F;&#x6548;&#xFF0C;&#x53E0;&#x52A0;&#x5230;&#x539F;&#x6709;&#x6837;&#x5F0F;&#x4E0A;&#xFF0C;&#x4F8B;&#x5B50;&#x4E2D;background-color&#x4F1A;&#x4ECE;&#x7EA2;&#x8272;&#x53D8;&#x6210;&#x7EFF;&#x8272;&#x3002;</p>
<h3 id="script&#x811A;&#x672C;">script&#x811A;&#x672C;</h3>
<p>&#x7528;&#x6765;&#x5B9A;&#x4E49;&#x9875;&#x9762;&#x6570;&#x636E;&#x548C;&#x5B9E;&#x73B0;&#x751F;&#x547D;&#x5468;&#x671F;&#x63A5;&#x53E3;&#x3002;</p>
<h4 id="&#x8BED;&#x6CD5;">&#x8BED;&#x6CD5;</h4>
<p>&#x652F;&#x6301;ES6&#x8BED;&#x6CD5;</p>
<p><strong>&#x4EE3;&#x7801;&#x5F15;&#x7528;</strong></p>
<p>NJS &#x4EE3;&#x7801;&#x5F15;&#x7528;&#x63A8;&#x8350;&#x4F7F;&#x7528; <code>import</code> &#x6765;&#x5BFC;&#x5165;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> utils <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;../Common/utils.njs&apos;</span>
</code></pre>
<h4 id="&#x5BF9;&#x8C61;">&#x5BF9;&#x8C61;</h4>
<p><strong>&#x81EA;&#x5B9A;&#x4E49;&#x6570;&#x636E;</strong></p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">data</td>
<td style="text-align:left">Object/Function</td>
<td style="text-align:left">&#x9875;&#x9762;&#x7684;&#x6570;&#x636E;&#x6A21;&#x578B;&#xFF0C;&#x80FD;&#x591F;&#x8F6C;&#x6362;&#x4E3A;JSON&#x5BF9;&#x8C61;&#xFF1B;&#x5C5E;&#x6027;&#x540D;&#x4E0D;&#x80FD;&#x4EE5;$&#x6216;_&#x5F00;&#x5934;&#xFF0C;&#x4E0D;&#x8981;&#x4F7F;&#x7528;for, if, show, tid&#x7B49;&#x4FDD;&#x7559;&#x5B57;&#x3002;&#x5982;&#x679C;&#x662F;&#x51FD;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x5FC5;&#x987B;&#x662F;&#x5BF9;&#x8C61;&#xFF0C;&#x5728;&#x9875;&#x9762;&#x521D;&#x59CB;&#x65F6;&#x56DE;&#x6267;&#x884C;&#x51FD;&#x6570;&#x83B7;&#x53D6;&#x7ED3;&#x679C;&#x4F5C;&#x4E3A;data&#x7684;&#x503C;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">props</td>
<td style="text-align:left">Array</td>
<td style="text-align:left">&#x7528;&#x4E8E;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;&#x7684;&#x516C;&#x5F00;&#x5C5E;&#x6027;&#x5217;&#x8868;&#xFF08;&#x5916;&#x90E8;&#x53EF;&#x89C1;&#xFF09;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>&lt;tag xxxx=&apos;value&apos;&gt;</code> &#x65B9;&#x5F0F;&#x4F20;&#x9012;&#x7ED9;&#x5230;&#x7EC4;&#x4EF6;&#x5185;&#x90E8;&#xFF1B;&#x5C5E;&#x6027;&#x540D;&#x5FC5;&#x987B;&#x5168;&#x90E8;&#x5C0F;&#x5199;&#xFF0C; &#x4E0D;&#x80FD;&#x4EE5;$&#x6216;_&#x5F00;&#x5934;&#xFF0C;&#x4E0D;&#x8981;&#x4F7F;&#x7528;for, if, show, tid&#x7B49;&#x4FDD;&#x7559;&#x5B57;&#x3002;&#x76EE;&#x524D;&#x516C;&#x5F00;&#x5C5E;&#x6027;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x4E0D;&#x652F;&#x6301;function&#x3002;</td>
</tr>
</tbody>
</table>
<p><strong>&#x516C;&#x5171;&#x5BF9;&#x8C61;</strong></p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">$app</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x5E94;&#x7528;&#x5BF9;&#x8C61;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$page</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x9875;&#x9762;&#x5BF9;&#x8C61;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$valid</td>
<td style="text-align:left">Boolean</td>
<td style="text-align:left">&#x9875;&#x9762;&#x5BF9;&#x8C61;&#x662F;&#x5426;&#x6709;&#x6548;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$visible</td>
<td style="text-align:left">Boolean</td>
<td style="text-align:left">&#x9875;&#x9762;&#x662F;&#x5426;&#x5904;&#x4E8E;&#x7528;&#x6237;&#x53EF;&#x89C1;&#x72B6;&#x6001;&#x3002;</td>
</tr>
</tbody>
</table>
<p><strong>&#x5E94;&#x7528;&#x5BF9;&#x8C61;</strong></p>
<p>&#x53EF;&#x901A;&#x8FC7; <code>$app</code> &#x8BBF;&#x95EE;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">$def</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x4F7F;&#x7528;this.$app.$def&#x83B7;&#x53D6;&#x5728;app.ux&#x4E2D;&#x66B4;&#x9732;&#x7684;&#x5BF9;&#x8C61;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$data</td>
<td style="text-align:left">Object</td>
<td style="text-align:left">&#x4F7F;&#x7528;this.$app.$data&#x83B7;&#x53D6;&#x5728;manifest.json&#x7684;config.data&#x4E2D;&#x58F0;&#x660E;&#x7684;&#x5168;&#x5C40;&#x6570;&#x636E;&#x3002;</td>
</tr>
</tbody>
</table>
<p><strong>&#x9875;&#x9762;&#x5BF9;&#x8C61;</strong></p>
<p>&#x53EF;&#x901A;&#x8FC7; <code>$page</code> &#x8BBF;&#x95EE;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">action</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x83B7;&#x53D6;&#x6253;&#x5F00;&#x5F53;&#x524D;&#x9875;&#x9762;&#x7684;action&#x3002;&#x4EC5;&#x5728;&#x5F53;&#x524D;&#x9875;&#x9762;&#x662F;&#x901A;&#x8FC7;filter&#x5339;&#x914D;&#x7684;&#x65B9;&#x5F0F;&#x6253;&#x5F00;&#x65F6;&#x6709;&#x6548;&#xFF0C;&#x5426;&#x5219;&#x4E3A;undefined&#x3002;&#x53C2;&#x89C1;&quot;manifest&#x6587;&#x4EF6;&quot;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">uri</td>
<td style="text-align:left">String</td>
<td style="text-align:left">&#x83B7;&#x53D6;&#x6253;&#x5F00;&#x5F53;&#x524D;&#x9875;&#x9762;&#x7684;uri&#x3002;&#x4EC5;&#x5728;&#x5F53;&#x524D;&#x9875;&#x9762;&#x662F;&#x901A;&#x8FC7;filter&#x5339;&#x914D;&#x7684;&#x65B9;&#x5F0F;&#x6253;&#x5F00;&#x65F6;&#x6709;&#x6548;&#xFF0C;&#x5426;&#x5219;&#x4E3A;undefined&#x3002;&#x53C2;&#x89C1;&quot;manifest&#x6587;&#x4EF6;&quot;&#x3002;</td>
</tr>
</tbody>
</table>
<h4 id="&#x65B9;&#x6CD5;">&#x65B9;&#x6CD5;</h4>
<p><strong>&#x6570;&#x636E;&#x65B9;&#x6CD5;</strong></p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">$set</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">key: String value: Any</td>
<td style="text-align:left">&#x6DFB;&#x52A0;&#x6570;&#x636E;&#x5C5E;&#x6027;&#xFF0C;&#x5FC5;&#x987B;&#x5728; onInit &#x51FD;&#x6570;&#x4E2D;&#x4F7F;&#x7528;&#xFF0C;&#x5426;&#x5219; <code>&lt;template&gt;</code> &#x4E2D;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x65E0;&#x6CD5;&#x751F;&#x6548;&#x7528;&#x6CD5; <code>this.$set(&apos;key&apos;, alue)</code> <code>this.$vm(&apos;id&apos;).$set(&apos;key&apos;,value)</code></td>
</tr>
<tr>
<td style="text-align:left">$delete</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">key: String</td>
<td style="text-align:left">&#x5220;&#x9664;&#x6570;&#x636E;&#x5C5E;&#x6027;&#xFF0C;&#x5982;&#x679C;&#x5728; onInit &#x51FD;&#x6570;&#x4E2D;&#x4F7F;&#x7528;&#xFF0C;&#x4F1A;&#x5BFC;&#x81F4; <code>&lt;template&gt;</code> &#x4E2D;&#x76F8;&#x5E94;&#x7684;&#x6570;&#x636E;&#x7ED1;&#x5B9A;&#x65E0;&#x6CD5;&#x751F;&#x6548;&#x7528;&#x6CD5; <code>this.$delete(&apos;key&apos;)</code> <code>this.$vm(&apos;id&apos;).$delete(&apos;key&apos;)</code></td>
</tr>
</tbody>
</table>
<p><strong>&#x516C;&#x5171;&#x65B9;&#x6CD5;</strong></p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">$element</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">id: String &#x7EC4;&#x4EF6;id</td>
<td style="text-align:left">&#x83B7;&#x53D6;&#x6307;&#x5B9A;id&#x7684;&#x7EC4;&#x4EF6;dom&#x5BF9;&#x8C61;&#xFF0C;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A;id&#xFF0C;&#x5219;&#x8FD4;&#x56DE;&#x6839;&#x7EC4;&#x4EF6;dom&#x5BF9;&#x8C61;&#x7528;&#x6CD5; <code>&lt;template&gt; &lt;div id=&apos;xxx&apos;&gt;&lt;/div&gt;&lt;/template&gt;</code>&#x3002;<code>this.$element(&apos;xxx&apos;)</code> &#x83B7;&#x53D6;id&#x4E3A;xxx&#x7684;div&#x7EC4;&#x4EF6;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x3002;<code>this.$element()</code> &#x83B7;&#x53D6;&#x6839;&#x7EC4;&#x4EF6;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$rootElement</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x83B7;&#x53D6;&#x6839;&#x7EC4;&#x4EF6;dom&#x5BF9;&#x8C61;&#x7528;&#x6CD5; <code>this.$rootElement()</code>&#xFF0C;&#x83B7;&#x53D6;&#x6839;&#x7EC4;&#x4EF6;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#xFF0C;&#x7B49;&#x540C;&#x4E8E; <code>this.$element()</code></td>
</tr>
<tr>
<td style="text-align:left">$vm</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">id: String &#x7EC4;&#x4EF6;id</td>
<td style="text-align:left">&#x83B7;&#x53D6;&#x6307;&#x5B9A; id &#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x7EC4;&#x4EF6;&#x7684; ViewModel &#x7528;&#x6CD5; <code>this.$vm(&apos;xxx&apos;)</code>&#xFF0C;&#x83B7;&#x53D6; id &#x4E3A;xxx&#x7684; div &#x7EC4;&#x4EF6; ViewModel&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$forceUpdate</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x5F3A;&#x5236;&#x9875;&#x9762;&#x5237;&#x65B0;</td>
</tr>
</tbody>
</table>
<p><strong>&#x4E8B;&#x4EF6;&#x65B9;&#x6CD5;</strong></p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">$on</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">type: String &#x4E8B;&#x4EF6;&#x540D;&#xFF0C;handler: Function &#x4E8B;&#x4EF6;&#x53E5;&#x67C4;&#x51FD;&#x6570;</td>
<td style="text-align:left">&#x6DFB;&#x52A0;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x53E5;&#x67C4;&#x7528;&#x6CD5; <code>this.$on(&apos;xxxx&apos;, this.fn)</code> &#xFF0C;fn &#x662F;&#x5728; <code>&lt;script&gt;</code> &#x4E2D;&#x5B9A;&#x4E49;&#x7684;&#x51FD;&#x6570;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$off</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">type: String &#x4E8B;&#x4EF6;&#x540D;&#xFF0C;handler: Function &#x4E8B;&#x4EF6;&#x53E5;&#x67C4;&#x51FD;&#x6570;</td>
<td style="text-align:left">&#x5220;&#x9664;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x53E5;&#x67C4;&#x7528;&#x6CD5; <code>this.$off(&apos;xxxx&apos;, this.fn)</code> &#xFF0C;<code>this.$off(&apos;xxx&apos;)</code>&#x5220;&#x9664;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x7684;&#x6240;&#x6709;&#x5904;&#x7406;&#x53E5;&#x67C4;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$dispatch</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">type: String &#x4E8B;&#x4EF6;&#x540D;</td>
<td style="text-align:left">&#x5411;&#x4E0A;&#x5C42;&#x7EC4;&#x4EF6;&#x53D1;&#x9001;&#x4E8B;&#x4EF6;&#x901A;&#x77E5;&#x7528;&#x6CD5; <code>this.$dispatch(&apos;xxx&apos;)</code> &#x6B63;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F1A;&#x4E00;&#x76F4;&#x5411;&#x4E0A;&#x4F20;&#x9012;&#x4E8B;&#x4EF6;&#xFF08;&#x5192;&#x6CE1;&#xFF09;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x505C;&#x6B62;&#x5192;&#x6CE1;&#xFF0C;&#x5728;&#x4E8B;&#x4EF6;&#x53E5;&#x67C4;&#x51FD;&#x6570;&#x4E2D;&#x8C03;&#x7528; <code>evt.stop()</code> &#x5373;&#x53EF;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$broadcast</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">type: String &#x4E8B;&#x4EF6;&#x540D;</td>
<td style="text-align:left">&#x5411;&#x5B50;&#x7EC4;&#x4EF6;&#x53D1;&#x9001;&#x4E8B;&#x4EF6;&#x901A;&#x77E5;&#x7528;&#x6CD5; <code>this.$broadcast(&apos;xxx&apos;)</code> &#x6B63;&#x5E38;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4F1A;&#x4E00;&#x76F4;&#x5411;&#x4E0B;&#x4F20;&#x9012;&#x4E8B;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x8981;&#x505C;&#x6B62;&#x4F20;&#x9012;&#xFF0C;&#x5728;&#x4E8B;&#x4EF6;&#x53E5;&#x67C4;&#x51FD;&#x6570;&#x4E2D;&#x8C03;&#x7528; <code>evt.stop()</code> &#x5373;&#x53EF;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$emit</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">type: String &#x4E8B;&#x4EF6;&#x540D;&#xFF0C;data: Object &#x4E8B;&#x4EF6;&#x53C2;&#x6570;</td>
<td style="text-align:left">&#x89E6;&#x53D1;&#x4E8B;&#x4EF6;&#xFF0C;&#x5BF9;&#x5E94;&#x7684;&#x53E5;&#x67C4;&#x51FD;&#x6570;&#x88AB;&#x8C03;&#x7528;&#x7528;&#x6CD5; <code>this.$emit(&apos;xxx&apos;)</code> &#xFF0C;<code>this.$emit(&apos;xxx&apos;, {a:1})</code>&#x4F20;&#x9012;&#x7684;&#x4E8B;&#x4EF6;&#x53C2;&#x6570;&#x53EF;&#x5728;&#x4E8B;&#x4EF6;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x901A;&#x8FC7; <code>evt.detail</code> &#x6765;&#x8BBF;&#x95EE;&#xFF0C;&#x4F8B;&#x5982; <code>evt.detail.a</code>&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$emitElement</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">type: String &#x4E8B;&#x4EF6;&#x540D;&#xFF0C;data: Object &#x4E8B;&#x4EF6;&#x53C2;&#x6570;&#xFF0C;id: String &#x7EC4;&#x4EF6;id (&#x9ED8;&#x8BA4;&#x4E3A;-1 &#x4EE3;&#x8868;&#x6839;&#x5143;&#x7D20;)</td>
<td style="text-align:left">&#x89E6;&#x53D1;&#x7EC4;&#x4EF6;&#x4E8B;&#x4EF6;, &#x5BF9;&#x5E94;&#x7684;&#x53E5;&#x67C4;&#x51FD;&#x6570;&#x88AB;&#x8C03;&#x7528;&#x7528;&#x6CD5; <code>this.$emitElement(&apos;xxx&apos;, null, &apos;id&apos;)</code>&#xFF0C; <code>this.$emitElement(&apos;xxx&apos;, {a:1})</code> &#x4F20;&#x9012;&#x7684;&#x4E8B;&#x4EF6;&#x53C2;&#x6570;&#x53EF;&#x5728;&#x4E8B;&#x4EF6;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x901A;&#x8FC7; <code>evt.detail</code> &#x6765;&#x8BBF;&#x95EE;&#xFF0C;&#x4F8B;&#x5982; <code>evt.detail.a</code>&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">$watch</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">data: String &#x5C5E;&#x6027;&#x540D;, &#x652F;&#x6301;&apos;a.b.c&apos;&#x683C;&#x5F0F;&#xFF0C;&#x4E0D;&#x652F;&#x6301;&#x6570;&#x7EC4;&#x7D22;&#x5F15;&#xFF0C;handler: String &#x4E8B;&#x4EF6;&#x53E5;&#x67C4;&#x51FD;&#x6570;&#x540D;, &#x51FD;&#x6570;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x65B0;&#x7684;&#x5C5E;&#x6027;&#x503C;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;&#x65E7;&#x7684;&#x5C5E;&#x6027;&#x503C;</td>
<td style="text-align:left">&#x52A8;&#x6001;&#x6DFB;&#x52A0;&#x5C5E;&#x6027;/&#x4E8B;&#x4EF6;&#x7ED1;&#x5B9A;&#xFF0C;&#x5C5E;&#x6027;&#x5FC5;&#x987B;&#x5728;data&#x4E2D;&#x5B9A;&#x4E49;&#xFF0C;handler&#x51FD;&#x6570;&#x5FC5;&#x987B;&#x5728; <code>&lt;script&gt;</code> &#x5B9A;&#x4E49;&#xFF1B;&#x5F53;&#x5C5E;&#x6027;&#x503C;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x4E8B;&#x4EF6;&#x624D;&#x88AB;&#x89E6;&#x53D1;&#x7528;&#x6CD5; <code>this.$watch(&apos;a&apos;,&apos;handler&apos;)</code></td>
</tr>
</tbody>
</table>
<p><strong>&#x9875;&#x9762;&#x65B9;&#x6CD5;</strong></p>
<p>&#x53EF;&#x901A;&#x8FC7; $page &#x8BBF;&#x95EE;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">setTitleBar</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">text: String &#x6807;&#x9898;&#x680F;&#x6587;&#x5B57;&#xFF0C;textColor: String &#x6587;&#x5B57;&#x989C;&#x8272;&#xFF0C;backgroundColor: String &#x80CC;&#x666F;&#x989C;&#x8272;&#xFF0C;backgroundOpacity: Number &#x900F;&#x660E;&#x5EA6;&#xFF0C;menu: Boolean &#x662F;&#x5426;&#x663E;&#x793A;&#x83DC;&#x5355;&#x6309;&#x94AE;</td>
<td style="text-align:left">&#x8BBE;&#x7F6E;&#x5F53;&#x524D;&#x9875;&#x9762;&#x7684;&#x6807;&#x9898;&#x680F;&#x7528;&#x6CD5; <code>this.$page.setTitleBar({text:&apos;Hello&apos;, textColor:&apos;#FF0000&apos;, backgroundColor:&apos;#FFFFFF&apos;,backgroundOpacity :0.5,menu: false})</code></td>
</tr>
</tbody>
</table>
<h4 id="&#x751F;&#x547D;&#x5468;&#x671F;&#x63A5;&#x53E3;">&#x751F;&#x547D;&#x5468;&#x671F;&#x63A5;&#x53E3;</h4>
<p><strong>&#x9875;&#x9762;&#x751F;&#x547D;&#x5468;&#x671F;</strong></p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x8FD4;&#x56DE;&#x503C;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
<th style="text-align:left">&#x89E6;&#x53D1;&#x65F6;&#x673A;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">onInit</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left"></td>
<td style="text-align:left"></td>
</tr>
<tr>
<td style="text-align:left">onInit</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x9875;&#x9762;&#x521D;&#x59CB;&#x5316;</td>
<td style="text-align:left">&#x5F53;&#x9875;&#x9762;&#x5B8C;&#x6210;&#x521D;&#x59CB;&#x5316;&#x65F6;&#x8C03;&#x7528;&#xFF0C;&#x53EA;&#x89E6;&#x53D1;&#x4E00;&#x6B21;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">onReady</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x9875;&#x9762;&#x521B;&#x5EFA;&#x5B8C;&#x6210;</td>
<td style="text-align:left">&#x5F53;&#x9875;&#x9762;&#x5B8C;&#x6210;&#x521B;&#x5EFA;&#x53EF;&#x4EE5;&#x663E;&#x793A;&#x65F6;&#x89E6;&#x53D1;&#xFF0C;&#x53EA;&#x89E6;&#x53D1;&#x4E00;&#x6B21;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">onShow</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x9875;&#x9762;&#x663E;&#x793A;</td>
<td style="text-align:left">&#x5F53;&#x8FDB;&#x5165;&#x9875;&#x9762;&#x65F6;&#x89E6;&#x53D1;</td>
</tr>
<tr>
<td style="text-align:left">onHide</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x9875;&#x9762;&#x9690;&#x85CF;</td>
<td style="text-align:left">&#x5F53;&#x9875;&#x9762;&#x8DF3;&#x8F6C;&#x79BB;&#x5F00;&#x65F6;&#x89E6;&#x53D1;</td>
</tr>
<tr>
<td style="text-align:left">onDestroy</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x9875;&#x9762;&#x9000;&#x51FA;</td>
<td style="text-align:left">&#x5F53;&#x9875;&#x9762;&#x8DF3;&#x8F6C;&#x79BB;&#x5F00;&#xFF08;&#x4E0D;&#x8FDB;&#x5165;&#x5BFC;&#x822A;&#x6808;&#xFF09;&#x65F6;&#x89E6;&#x53D1;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">onBackPress</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">Boolean</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x8FD4;&#x56DE;&#x6309;&#x94AE;&#x52A8;&#x4F5C;</td>
<td style="text-align:left">&#x5F53;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x8FD4;&#x56DE;&#x6309;&#x94AE;&#x65F6;&#x89E6;&#x53D1;&#x3002;&#x8FD4;&#x56DE;true&#x8868;&#x793A;&#x9875;&#x9762;&#x81EA;&#x5DF1;&#x5904;&#x7406;&#x8FD4;&#x56DE;&#x903B;&#x8F91;&#xFF0C;&#x8FD4;&#x56DE;false&#x8868;&#x793A;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x7684;&#x8FD4;&#x56DE;&#x903B;&#x8F91;&#xFF0C;&#x4E0D;&#x8FD4;&#x56DE;&#x503C;&#x4F1A;&#x4F5C;&#x4E3A;false&#x5904;&#x7406;&#x3002;</td>
</tr>
<tr>
<td style="text-align:left">onMenuPress</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x83DC;&#x5355;&#x6309;&#x94AE;&#x52A8;&#x4F5C;</td>
<td style="text-align:left">&#x5F53;&#x7528;&#x6237;&#x70B9;&#x51FB; ActionBar &#x53F3;&#x8FB9;&#x83DC;&#x5355;&#x6309;&#x94AE;&#x65F6;&#x89E6;&#x53D1;</td>
</tr>
<tr>
<td style="text-align:left">onOrientationChange</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x8BBE;&#x5907;&#x5C4F;&#x5E55;&#x65CB;&#x8F6C;</td>
<td style="text-align:left">&#x7528;&#x6237;&#x5782;&#x76F4;&#x6216;&#x6C34;&#x5E73;&#x65CB;&#x8F6C;&#x79FB;&#x52A8;&#x8BBE;&#x5907;&#x65F6;&#x88AB;&#x89E6;&#x53D1;&#xFF0C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x4F20;&#x5165;&#x5BF9;&#x8C61; ScreenOrientation &#x6765;&#x63CF;&#x8FF0;&#x5F53;&#x524D;&#x5C4F;&#x5E55;&#x8F6C;&#x5411;&#x4FE1;&#x606F;&#x3002;</td>
</tr>
</tbody>
</table>
<p><code>ScreenOrientation.type</code> &#x63CF;&#x8FF0;&#x5F53;&#x524D;&#x8F6C;&#x5411;&#x7C7B;&#x578B;</p>
<ul>
<li>portraitprimary</li>
<li>portraitsecondary</li>
<li>landscapeprimary</li>
<li>landscapesecondary</li>
</ul>
<p><code>ScreenOrientation.angle</code> &#x63CF;&#x8FF0;&#x5F53;&#x524D;&#x8F6C;&#x5411;&#x89D2;&#x5EA6;</p>
<p>&#x9875;&#x9762;&#x7684;&#x751F;&#x547D;&#x5468;&#x671F;&#x63A5;&#x53E3;&#x7684;&#x8C03;&#x7528;&#x987A;&#x5E8F;&#xFF1A;</p>
<ul>
<li>&#x6253;&#x5F00;&#x9875;&#x9762;A&#xFF1A;onInit() -&gt; onReady() -&gt; onShow()</li>
<li>&#x5728;&#x9875;&#x9762;A&#x6253;&#x5F00;&#x9875;&#x9762;B&#xFF1A;onHide()</li>
<li>&#x4ECE;&#x9875;&#x9762;B&#x8FD4;&#x56DE;&#x9875;&#x9762;A&#xFF1A;onShow()</li>
<li>A&#x9875;&#x9762;&#x8FD4;&#x56DE;&#xFF1A;onBackPress() -&gt; onHide() -&gt; onDestroy()</li>
</ul>
<p><strong>&#x5E94;&#x7528;&#x751F;&#x547D;&#x5468;&#x671F;</strong></p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x5C5E;&#x6027;</th>
<th style="text-align:left">&#x7C7B;&#x578B;</th>
<th style="text-align:left">&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x8FD4;&#x56DE;&#x503C;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
<th style="text-align:left">&#x89E6;&#x53D1;&#x65F6;&#x673A;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">onCreate</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x5E94;&#x7528;&#x521B;&#x5EFA;</td>
<td style="text-align:left">&#x5F53;&#x5E94;&#x7528;&#x521B;&#x5EFA;&#x65F6;&#x8C03;&#x7528;</td>
</tr>
<tr>
<td style="text-align:left">onDestroy</td>
<td style="text-align:left">Function</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x65E0;</td>
<td style="text-align:left">&#x76D1;&#x542C;&#x5E94;&#x7528;&#x9500;&#x6BC1;</td>
<td style="text-align:left">&#x5F53;&#x5E94;&#x7528;&#x9500;&#x6BC1;&#x65F6;&#x89E6;&#x53D1;</td>
</tr>
</tbody>
</table>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="nml.html" class="navigation navigation-prev navigation-unique" aria-label="Previous page: nml文件">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"页面与组件","level":"1.3.4","depth":2,"next":{"title":"组件","level":"1.4","depth":1,"ref":"","articles":[{"title":"通用","level":"1.4.1","depth":2,"path":"component/general.md","ref":"component/general.md","articles":[]},{"title":"容器组件","level":"1.4.2","depth":2,"path":"component/container.md","ref":"component/container.md","articles":[]},{"title":"基础组件","level":"1.4.3","depth":2,"path":"component/basics.md","ref":"component/basics.md","articles":[]},{"title":"表单组件","level":"1.4.4","depth":2,"path":"component/form.md","ref":"component/form.md","articles":[]},{"title":"媒体组件","level":"1.4.5","depth":2,"path":"component/media.md","ref":"component/media.md","articles":[]}]},"previous":{"title":"nml文件","level":"1.3.3","depth":2,"path":"framework/nml.md","ref":"framework/nml.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"framework/page.md","mtime":"2018-02-25T08:27:31.960Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-03-21T12:50:57.603Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

